import { getIntl, request } from "@umijs/max";
import { message } from "antd";

export async function pagedLog(
    params: {
        current?: number;
        pageSize?: number;
    },
    options?: { [key: string]: any },
) {
    const intl = getIntl();
    try {
        const response = await request<API.ApiResponse>('/admin-api/system/operate-log/page', {
            method: 'GET',
            params: {
                ...params,
            },
            ...(options || {}),
        });

        if (response?.code !== 0) {
            message.error(response?.msg + intl.formatMessage({ id: 'request.error.default' }));
            return [];
        }

        return response?.data || [];
    } catch (error) {
        message.error(intl.formatMessage({ id: 'request.error.network' }));
        return [];
    }
}


export async function pagedApiLog(
    params: {
        current?: number;
        pageSize?: number;
    },
    options?: { [key: string]: any },
) {
    const intl = getIntl();
    try {
        const response = await request<API.ApiResponse>('/admin-api/system/truck-log/api-page', {
            method: 'GET',
            params: {
                ...params,
            },
            ...(options || {}),
        });

        if (response?.code !== 0) {
            message.error(response?.msg + intl.formatMessage({ id: 'request.error.default' }));
            return [];
        }

        return response?.data || [];
    } catch (error) {
        message.error(intl.formatMessage({ id: 'request.error.network' }));
        return [];
    }
}



export async function pagedOrderLog(
    params: {
        current?: number;
        pageSize?: number;
    },
    options?: { [key: string]: any },
) {
    const intl = getIntl();
    try {
        const response = await request<API.ApiResponse>('/admin-api/system/truck-log/order-page', {
            method: 'GET',
            params: {
                ...params,
            },
            ...(options || {}),
        });

        if (response?.code !== 0) {
            message.error(response?.msg + intl.formatMessage({ id: 'request.error.default' }));
            return [];
        }

        return response?.data || [];
    } catch (error) {
        message.error(intl.formatMessage({ id: 'request.error.network' }));
        return [];
    }
}